home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 May / CMCD0504.ISO / Software / Freeware / Programare / gdiplusdelphi / demos / Using Images, Bitmaps, and Metafiles / Cropping and Scaling Images / GDITEST39.dpr
Encoding:
Text File  |  2003-10-15  |  3.0 KB  |  112 lines

  1. program GDITEST39;
  2.  
  3. uses
  4.   Classes,
  5.   Windows,
  6.   Messages,
  7.   SysUtils,
  8.   GDIPAPI,
  9.   GDIPOBJ;
  10.  
  11. Procedure OnPaint(DC: HDC);
  12. var
  13.   graphics : TGPGraphics;
  14.   Image: TGPImage;
  15.   width, height: UINT;
  16.   destinationRect: TGPRectF;
  17. begin
  18.   graphics := TGPGraphics.Create(DC);
  19.   Image:= TGPImage.Create('..\..\Media\Apple.gif');
  20.   width := image.GetWidth;
  21.   height := image.GetHeight;
  22.  
  23.   // Make the destination rectangle 30 percent wider and
  24.   // 30 percent taller than the original image.
  25.   // Put the upper-left corner of the destination
  26.   // rectangle at (150, 20).
  27.   destinationRect := MakeRect(150, 20, 1.3 * width, 1.3 * height);
  28.  
  29.   // Draw the image unaltered with its upper-left corner at (0, 0).
  30.   graphics.DrawImage(image, 0, 0);
  31.  
  32.   // Draw a portion of the image. Scale that portion of the image
  33.   // so that it fills the destination rectangle.
  34.   graphics.DrawImage(
  35.     image,
  36.     destinationRect,
  37.     0, 0,              // upper-left corner of source rectangle
  38.     0.75 * width,      // width of source rectangle
  39.     0.75 * height,     // height of source rectangle
  40.     UnitPixel);
  41.  
  42.   Image.Free;  
  43.   graphics.Free;
  44. end;
  45.  
  46.  
  47. function WndProc(Wnd : HWND; message : UINT; wParam : Integer; lParam: Integer) : Integer; stdcall;
  48. var
  49.   Handle: HDC;
  50.   ps: PAINTSTRUCT;
  51. begin
  52.   case message of
  53.     WM_PAINT:
  54.       begin
  55.         Handle := BeginPaint(Wnd, ps);
  56.         OnPaint(Handle);
  57.         EndPaint(Wnd, ps);
  58.         result := 0;
  59.       end;
  60.  
  61.     WM_DESTROY:
  62.       begin
  63.         PostQuitMessage(0);
  64.         result := 0;
  65.       end;
  66.  
  67.    else
  68.       result := DefWindowProc(Wnd, message, wParam, lParam);
  69.    end;
  70. end;
  71.  
  72. var
  73.   hWnd     : THandle;
  74.   Msg      : TMsg;
  75.   wndClass : TWndClass;
  76. begin
  77.    wndClass.style          := CS_HREDRAW or CS_VREDRAW;
  78.    wndClass.lpfnWndProc    := @WndProc;
  79.    wndClass.cbClsExtra     := 0;
  80.    wndClass.cbWndExtra     := 0;
  81.    wndClass.hInstance      := hInstance;
  82.    wndClass.hIcon          := LoadIcon(0, IDI_APPLICATION);
  83.    wndClass.hCursor        := LoadCursor(0, IDC_ARROW);
  84.    wndClass.hbrBackground  := HBRUSH(GetStockObject(WHITE_BRUSH));
  85.    wndClass.lpszMenuName   := nil;
  86.    wndClass.lpszClassName  := 'GettingStarted';
  87.  
  88.    RegisterClass(wndClass);
  89.  
  90.    hWnd := CreateWindow(
  91.       'GettingStarted',       // window class name
  92.       'Cropping and Scaling Images',       // window caption
  93.       WS_OVERLAPPEDWINDOW,    // window style
  94.       Integer(CW_USEDEFAULT), // initial x position
  95.       Integer(CW_USEDEFAULT), // initial y position
  96.       Integer(CW_USEDEFAULT), // initial x size
  97.       Integer(CW_USEDEFAULT), // initial y size
  98.       0,                      // parent window handle
  99.       0,                      // window menu handle
  100.       hInstance,              // program instance handle
  101.       nil);                   // creation parameters
  102.  
  103.    ShowWindow(hWnd, SW_SHOW);
  104.    UpdateWindow(hWnd);
  105.  
  106.    while(GetMessage(msg, 0, 0, 0)) do
  107.    begin
  108.       TranslateMessage(msg);
  109.       DispatchMessage(msg);
  110.    end;
  111. end.
  112.